package com.ymatou.iapi.trading.sellerquery2.parameter.sp;

import java.util.List;
import java.util.Map;

import com.ymttest.database.sqlwapper.YmtOrdersWapper;
import com.ymttest.utils.DataUtil;

/**
 * 存储过程[sp_trd_GetSellerOrderCount]
 * 
 * @author songyefeng
 *
 */
public class Sp_GetSellerOrderCount {
	private int sellerId;
	private Boolean isShangouOrder;
	private String beginTime;
	private String endTime;
	private List<Integer> orderStatus;

	public int getSellerId() {
		return sellerId;
	}

	public void setSellerId(int sellerId) {
		this.sellerId = sellerId;
	}

	public Boolean getIsShangouOrder() {
		return isShangouOrder;
	}

	public void setIsShangouOrder(Boolean isShangouOrder) {
		this.isShangouOrder = isShangouOrder;
	}

	public String getBeginTime() {
		return beginTime;
	}

	public void setBeginTime(String beginTime) {
		this.beginTime = beginTime;
	}

	public String getEndTime() {
		return endTime;
	}

	public void setEndTime(String endTime) {
		this.endTime = endTime;
	}

	public List<Integer> getOrderStatus() {
		return orderStatus;
	}

	public void setOrderStatus(List<Integer> orderStatus) {
		this.orderStatus = orderStatus;
	}

	@SuppressWarnings("rawtypes")
	public List<Map> execute() {
		YmtOrdersWapper ymtOrdersWapper = new YmtOrdersWapper();
		String queryField = "o.iTradingStatus, cast(1 as bit) as bPaidInFull, COUNT(o.iOrderId) as orderCount";
		//砍价团订单，在组团成功前，不展示结果
		String joinCondition = "LEFT JOIN dbo.Ymt_OrderBiz b ON b.OrderId = o.iOrderId ";
		StringBuffer queryCondition = new StringBuffer();
		queryCondition
				.append("( b.OrderId IS NULL OR b.BizStatus =3)  and iBuyerId = "
						+ sellerId);
		if (beginTime != null) {
			queryCondition.append(" and dAddTime >= '" + beginTime + "'");
		}
		if (endTime != null) {
			queryCondition.append(" and dAddTime <= '" + endTime + "'");
		}
		//		if(isShangouOrder != null){
		//			queryCondition.append(" and bShangouOrder = "+DataUtil.bool2Int(isShangouOrder));
		//		}
		if (DataUtil.isNullOrEmpty(orderStatus) == false) {
			queryCondition.append(" and iTradingStatus in "
					+ DataUtil.toInOfSql(orderStatus));
		}
		queryCondition.append(" group by iTradingStatus");
		return ymtOrdersWapper.selectOrders2(queryField, joinCondition,
				queryCondition.toString());
	}

}
